package ccpvspiral1;

import java.util.ArrayList;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import org.jscience.physics.amount.Amount;
import repast.simphony.context.Context;
import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.space.gis.Geography;
import repast.simphony.random.RandomHelper;
import repast.simphony.annotate.AgentAnnot;
import repast.simphony.ui.probe.ProbeID;
import repast.simphony.util.ContextUtils;

import javax.measure.unit.SI;

@AgentAnnot(displayName = "Geo Agent")
public class GisAgent {
	// Static variables
	private static ArrayList2D ascriptiveCharsList = new ArrayList2D();
	private static MockFunction mockF = new MockFunction();
	private static ArrayList2D ascriptiveBuckets = new ArrayList2D();

	// Instance variables
	private int[] ascriptiveChars; 

	private String name;
	private int age;
	// This is the intended group for an agent
	private int group;
	// Value is the int we track for all displaying purposes
	private int value;
	// boolean for toggling group
	private boolean groupToggle = true;
	// Boolean for testing purposes
	private boolean test = false;

	private int violence;
	// This is the current group the agent is associated with
	private int currentGroup = -1; 

	public GisAgent() {
		violence = 100;
		value = currentGroup;
	}

	// Assumes the user already setup the ArrayList2D to start
	public static void setClassAscriptiveChars(ArrayList2D newAscriptives)
	{
		ascriptiveCharsList = newAscriptives;
		/*
		// setup buckets to reflect new class ascriptives... basically it will
		// be an ArrayList of TaggedList of TaggedList of GisAgent
		for (int i = 0; i < newAscriptives.size(); i++)
		{
			TaggedList currentAscriptiveType = newAscriptives.get(i);
			String currentAscriptiveTypeString = currentAscriptiveType.getTag();
			TaggedList<TaggedList> newAscriptiveType = new TaggedList<TaggedList>(currentAscriptiveTypeString);
			
			for (int j = 0; j < currentAscriptiveType.size(); i++)
			{
				String currentAscriptive = (String)currentAscriptiveType.get(j);
				TaggedList<GisAgent> aBucket = new TaggedList<GisAgent>(currentAscriptive);
				newAscriptiveType.add(aBucket);
			}
			
			ascriptiveBuckets.add(newAscriptiveType);
		}
		*/
	}
	
	// Add the agent to all appropriate buckets
	public static void addAgentToBuckets(GisAgent newAgent)
	{
		int[] agentAscriptives = newAgent.getAgentAscriptiveInts();
		for (int i = 0; i < agentAscriptives.length; i++)
		{
			TaggedList toBucket = (TaggedList)ascriptiveBuckets.get(i).get(agentAscriptives[i]);
			toBucket.add(newAgent);
		}
	}
		
	public void setAgentAscriptiveChars(int[] newAgentAscriptives)
	{
		if (newAgentAscriptives.length == ascriptiveCharsList.size())
			ascriptiveChars = newAgentAscriptives;
		else
			System.out.println("new ascriptive list is not equal to ascriptive characteristics list");
	}
	
	public ArrayList<String> getAgentAscriptiveStrings()
	{
		ArrayList ret = new ArrayList();
		for(int i = 0; i < ascriptiveChars.length; i++)
		{
			ret.add(ascriptiveCharsList.get(i).get(ascriptiveChars[i]));
		}
		
		return ret;
	}
	
	public int[] getAgentAscriptiveInts()
	{
		return ascriptiveChars;
	}
	
	public static ArrayList2D getAscriptiveCharsList()
	{
		return ascriptiveCharsList;
	}
	
	@ProbeID
	public String getName() 
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public double getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getViolence()
	{
		return violence;
	}

	public void setViolence(int violence)
	{
		this.violence = violence;
	}

	public int getGroup()
	{
		return group;
	}

	public void setGroup(int group)
	{
		this.group = group;
	}

	public int getCurrentGroup()
	{
		return currentGroup;
	}

	public void setCurrentgroup(int currentGroup)
	{
		this.currentGroup = currentGroup;
	}

	public int getValue()
	{
		return value;
	}

	public void setValue(int value)
	{
		this.value = value;
	}

	public boolean getTest()
	{
		return test;
	}

	public void switchTest()
	{
		test = !test;
		if (test)
			value = violence;
		else
			value = group;
	}

	public void toggleGroup()
	{
		groupToggle = !groupToggle;
	}

	public double calcDist(Coordinate a, Coordinate b)
	{
		return Math.sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
	}

	@ScheduledMethod(start = 1, pick = 1, interval = 1)
	public void step() {
		value++;
	
	}
}

